package ysw.action;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import ysw.vo.*;
import ysw.jdbc.AppointmentJdbc;
import org.apache.struts2.ServletActionContext;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

public class AppointmentAction extends ActionSupport {
  private static final long serialVersionUID = 1L;
	private Appointment appointment;

    public Appointment getAppointment() {
        return appointment;
    }

    public void setAppointment(Appointment appointment) {
        this.appointment = appointment;
    }
  
    
  private List<Appointment>  appointmentList;

      
    

 public String execute() throws Exception{
  
      AppointmentJdbc appointmentJ=new AppointmentJdbc();
             
        appointment.setCid(appointment.getCid());
        appointment.setCname(appointment.getCname());
        appointment.setCarnumber(appointment.getCarnumber());
        appointment.setReason(appointment.getReason()); 
        appointment.setResul(appointment.getResul());
      
        appointmentJ.addAppointment(appointment);
       
        return SUCCESS;
    }

 public String showAllAppointment()throws Exception{
   
	Appointment appointment1=new Appointment();
        AppointmentJdbc appointmentJ=new AppointmentJdbc();
        try{
            appointmentList=appointmentJ.showAppointment();
        }catch(SQLException e){
            e.printStackTrace();
        }
   
	Map request=(Map)ActionContext.getContext().get("request");
        request.put("appointmentList",appointmentList);
  
        return SUCCESS;
    }
 public String showOneAppointment() throws Exception{
     Appointment appointment1=new Appointment();
     AppointmentJdbc appointmentJ=new AppointmentJdbc();
     appointment1=appointmentJ.showOneAppointment(appointment.getAppid());

     Map request=(Map)ActionContext.getContext().get("request");
     request.put("appointment1",appointment1);
     return SUCCESS;


}
  public String printAppointment() throws Exception{
     Appointment appointment1=new Appointment();
     AppointmentJdbc appointmentJ=new AppointmentJdbc();
     appointment1=appointmentJ.printAppointment(appointment.getAppid());

     Map request=(Map)ActionContext.getContext().get("request");
     request.put("appointment1",appointment1);
     return SUCCESS;


}
 public String updateSaveAppointment() throws Exception{
   AppointmentJdbc appointmentJ=new AppointmentJdbc();
   
    appointment.setAppid(appointment.getAppid()); 
    appointment.setCid(appointment.getCid());
    appointment.setCname(appointment.getCname());
    appointment.setCarnumber(appointment.getCarnumber());
    appointment.setReason(appointment.getReason());
    appointment.setResul(appointment.getResul());
    appointment.setZuofei(appointment.getZuofei());
    
    appointmentJ.updateSaveAppointment(appointment);
    return SUCCESS;
}
}
